package com.dfiov.cloud.msmtools.service.business.impl;

import com.alibaba.fastjson.JSON;
import com.dfiov.cloud.msmtools.entity.vo.msmtools.OpUserVo;
import com.dfiov.cloud.msmtools.mapper.msoptaccountMapper.OpUserMapper;
import com.dfiov.cloud.msmtools.mapper.entity.msmtools.OptUserDo;
import com.dfiov.cloud.msmtools.service.business.OpUserService;
import com.pateo.qingcloud.framework.common.base.BaseRestResponse;
import com.pateo.qingcloud.framework.common.statusCode.CommonStatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.dfiov.cloud.msmtools.contant.Constants.Modification_Failed;
import static com.dfiov.cloud.msmtools.contant.Constants.Modification_Failed_MSG;


@Slf4j
@Service
public class OpUserServiceImpl implements OpUserService {

    @Resource
    OpUserMapper opUserMapper;

    @Override
    public BaseRestResponse<OptUserDo> getOpUser(OpUserVo opUserVo) {
        OptUserDo opUser = opUserMapper.getOpUser(
                opUserVo.getRealName(),
                opUserVo.getPhone(),
                opUserVo.getUsername(),
                opUserVo.getOrgCode());
        log.info("getOpUser::OpUser::"+ JSON.toJSONString(opUser));
        return new BaseRestResponse<>(CommonStatusCode.SUCCESS0.getCode(), CommonStatusCode.SUCCESS0.getDetail(), opUser);
    }

    @Override
    public BaseRestResponse<String> updateOpUserLockStatus(String userName) {
        long count = opUserMapper.updateOpUserLockStatus(userName);
        if (count == 0) {
            return new BaseRestResponse<>(Modification_Failed, Modification_Failed_MSG, null);
        }else {
            log.info("updateOpUserLockStatus::userName::"+ userName+" success");
            return new BaseRestResponse<>(CommonStatusCode.SUCCESS0.getCode(), CommonStatusCode.SUCCESS0.getDetail(), userName);
        }
    }

}
